import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import vueDevTools from 'vite-plugin-vue-devtools'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    vueDevTools(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
  server: {
    proxy: {
      '/api': {
        // target: 'http://127.0.0.1:8698/storage',
        // target: 'http://192.168.142.100:8698/storage',
        target: 'http://192.168.43.117:8698/storage',
        changeOrigin: true,
        // 统一重写：去掉 /api 前缀，使前端 /api/* 映射为后端 /storage/*
        // 示例：/api/backup-strategy => /storage/backup-strategy
        //      /api/backup-strategy/page => /storage/backup-strategy/page
        //      /api/metrics/metrics-info => /storage/metrics/metrics-info
        rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  }
})
